package com.example.joke.custom.stepview

import android.animation.ObjectAnimator
import android.animation.ValueAnimator
import android.view.animation.DecelerateInterpolator
import com.example.joke.base.navigationbar.AbsNavigationBar
import com.example.joke.databinding.ActivityQqStepBinding
import com.example.joke.frame.BaseSkinActivity
import com.example.joke.frame.DefaultNavigationBar

class QQStepActivity : BaseSkinActivity<ActivityQqStepBinding>() {

    override fun setListener() {
    }

    override fun initData() {
        binding.qq.mStepMax = 6000
//        binding.qq.mCurrentQQStep = 2000
        // 使用下面这句代码在 it.animatedValue as Int 时会造成：
        // Caused by: java.lang.ClassCastException: java.lang.Float cannot be cast to java.lang.Integer
//        val valueAnimator: ValueAnimator = ObjectAnimator.ofFloat(0f, 2000f)
        val valueAnimator: ValueAnimator = ObjectAnimator.ofInt(0, 2000)
        valueAnimator.duration = 1500
        valueAnimator.interpolator = DecelerateInterpolator()
        valueAnimator.addUpdateListener {
            binding.qq.mCurrentQQStep = it.animatedValue as Int
        }
        valueAnimator.start()
    }

    override fun initTitle() {
        DefaultNavigationBar.Builder(this)
            .setTitle("仿QQ步数进度效果")
            .builder<AbsNavigationBar.Builder.AbsNavigationParams>()
    }

    override fun getBinding1(): ActivityQqStepBinding {
        return ActivityQqStepBinding.inflate(layoutInflater)
    }
}